<script setup>
import axios from 'axios'
import { ref } from 'vue'
// 1. 渲染表格数据
const list = ref([])
const getList = async () => {
  const res = await axios.get('/list')
  list.value = res.data
}

// 2. 做删除功能
const deleteFn = async (id) => {
 console.log(id);
  await axios.delete(`/del?id=${id}`)
  getList()
}


getList()
</script>

<template>
  <div class="app">
    <el-table :data="list">
      <el-table-column label="ID" prop="id"></el-table-column>
      <el-table-column label="姓名" prop="name" width="150"></el-table-column>
      <el-table-column label="籍贯" prop="place"></el-table-column>
      <el-table-column label="操作">
        <template v-slot="{row}">
          <el-button type="primary" @click="deleteFn(row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<style>
.app {
  width: 980px;
  margin: 100px auto 0;
}
</style>